<?php
/**
 * Created by PhpStorm.
 * User: zwh
 * Time: 2016-11-11 10:56:12
 */
class BusinessItem extends Eloquent
{
    protected $table = "business_item";
    
    public static function allow_bi($shop_id){
        $date = date("Y-m-d");
        $all_shop_bi = BusinessItem::where("region_type",1)
                ->select("business_item.id")
                ->where(function($query) use ($date){
                $query->where('period_type',1)
                      ->orwhere(function($query)  use ($date){
                          $query->where('period_type',2)
                                  ->where('start_date',"<",$date)
                                  ->where('end_date',">",$date);
                      });
                })->get()->toArray();
        
        $shop_bi = BusinessItem::where("region_type",2)
                ->select("business_item.id")
                ->leftJoin("bi_item_shops as bis","bis.bi_id","=","business_item.id")
                ->where("bis.shop_id","=",$shop_id)
                ->where(function($query) use ($date){
                $query->where('period_type',1)
                      ->orwhere(function($query)  use ($date){
                          $query->where('period_type',2)
                                  ->where('start_date',"<",$date)
                                  ->where('end_date',">",$date);
                      });
            })->get()->toArray();
        $id_list = array_merge($all_shop_bi,$shop_bi);
        return $id_list;
    }

}